﻿using System.Reflection;
using OnHook.Business.IServices.Auth;
using OnHook.Business.IServices.Pay;
using OnHook.Business.Services.Auth;
using OnHook.Business.Services.Pay;
using OnHook.Domain;
using OnHook.Domain.Enums;
using OnHook.Framework;
using OnHook.Framework.Extensions;
using OnHook.Framework.Module;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace OnHook.Business
{
    /// <summary>
    /// 业务模块
    /// </summary>
    public class BusinessModule : ProgrameModule
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        public override void PreInit(BootParams model)
        {
            model.Services.RegsiterAssembly(Assembly.GetExecutingAssembly());
            model.Services.AsNamedServiceProvider()
                .AddNamedService<IOpenAuthService, WechatAuthService>(EnumPlatform.Wechat.ToString(), ServiceLifetime.Scoped)
                .AddNamedService<IPayService,WechatPayService>(EnumPlatform.Wechat.ToString(), ServiceLifetime.Scoped)
                .AddNamedService<IPayService, AliPayService>(EnumPlatform.Alipay.ToString(), ServiceLifetime.Scoped)
                .Build();
            //Redis初始化
            var redisConnectString = model.Configuration.GetConnectionString(AppConsts.REDIST_CONNECTSTRING_NODE);
            var csredis = new CSRedis.CSRedisClient(redisConnectString);
            RedisHelper.Initialization(csredis);
        }

    }
}
